package com.lmx.repoDomain.tmodel;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToOne;

/**
 * 睡眠信息
 */
@JsonApiResource(type = "sleepmessage")
@Table(name = "tnb_sleepdata")
@Entity
public class SleepMessage extends BaseEntity {

	private Integer createDateTime;	// 数据创建时间

	private String deviceId;		// 按键ID 与老人按键绑定

	private Integer lastUpdateDateTime;// 更新时间
	
	private Integer createDate;		// 统计日期
	
	private Integer deepSleepMins;	// 深睡眠时间
	
	private Integer lightSleepMins;	// 浅睡眠时间

	private Integer allSleepMins;	// 睡眠时间
	
	private Integer wakeUpMins;		// 醒着的时间
	
	private Bed bed;// 床位编号 需要关联bed表 id

	private Customer customer;		// 用户

	@Column(name = "createDateTime")
	public Integer getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(Integer createDateTime) {
		this.createDateTime = createDateTime;
	}

	@Column(name = "lastUpdateDateTime")
	public Integer getLastUpdateDateTime() {
		return lastUpdateDateTime;
	}

	public void setLastUpdateDateTime(Integer lastUpdateDateTime) {
		this.lastUpdateDateTime = lastUpdateDateTime;
	}

	@Column(name = "deviceId")
	public String getDeviceId() {
		return deviceId;
	}

	public void setDeviceId(String deviceId) {
		this.deviceId = deviceId;
	}

	public SleepMessage() {
	}
	
	@Column(name = "deepSleepMins")
	public Integer getDeepSleepMins() {
		return deepSleepMins;
	}

	public void setDeepSleepMins(Integer deepSleepMins) {
		this.deepSleepMins = deepSleepMins;
	}

	@Column(name = "lightSleepMins")
	public Integer getLightSleepMins() {
		return lightSleepMins;
	}

	public void setLightSleepMins(Integer lightSleepMins) {
		this.lightSleepMins = lightSleepMins;
	}

	@Column(name = "wakeUpMins")
	public Integer getWakeUpMins() {
		return wakeUpMins;
	}

	public void setWakeUpMins(Integer wakeUpMins) {
		this.wakeUpMins = wakeUpMins;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "customer_id", foreignKey = @ForeignKey(name = "null"))
	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@Column(name = "createDate")
	public Integer getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Integer createDate) {
		this.createDate = createDate;
	}

	@Column(name = "allSleepMins")
	public Integer getAllSleepMins() {
		return allSleepMins;
	}

	public void setAllSleepMins(Integer allSleepMins) {
		this.allSleepMins = allSleepMins;
	}
	
	@JsonApiToOne
	@JsonApiIncludeByDefault
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name = "bed_id", foreignKey = @ForeignKey(name = "null"))
	public Bed getBed() {
		return bed;
	}

	public void setBed(Bed bed) {
		this.bed = bed;
	}
}
